package com.example.kt_base.s6

//TODO 106.Kotlin语言的泛型变换实战
class KtBase106<T>(val isMap: Boolean, val input: T) {

    //模仿RxJava T是要变化的输入类型 R是变化后的输出类型
    //要支map返回的类型是R？
 //  inline fun <R> map(mapAction: (T) -> R) = mapAction(input).takeIf { isMap }
    inline fun <R> map(mapAction: (T) -> R): R {
        val mapActioon1 = mapAction(input)
        return mapActioon1
    }

}
data class Persons(val name:String,val age:Int)
data class Student2(val name:String,val age:Int)
fun main() {
    val p = KtBase106(isMap = true, input = 153)
    p.map {
        println(it)
    }

    val r=KtBase106(true,Persons("jenny",15))
   val r2 = r.map {
      Student2(it.name,it.age)
    }
    println(r2)

}
